home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 41.zip / BS1 part 41 / Lattice C v5.02 d4.adf / examples / debugger / showprocess.cpr < prev    next >
Text File  |  1988-11-07  |  6KB  |  196 lines

  1. /* 
  2. Usage: ShowProcess [<task name> | 0xnnnnnnnn]
  3. Version 1.01  04-Nov-88
  4.  
  5. Displays the process structure for the given task.  If none is specified,
  6. the current task under debugger control is displayed.  ShowProcess will
  7. verify that the indicated task is a valid process before displaying the
  8. information.
  9.  
  10. Note that because of the Amiga Scheduling, ShowProcess may not always be
  11. able to find a task specified by name.
  12.  
  13. Output is displayed in the form:
  14. --------------------------------
  15. 'RAW' in wait state at priority 5
  16. Type 13  Flags 00  IDNestCnt 0  TDNestCnt -1
  17. Signal:  Alloc 0000FFFF  Wait  00000100  Recvd 00000000  Except 00000000
  18. Trap:    Data  00000000  Code  00FF47EA  Alloc 8000  Able 0000
  19. Except:  Data  00000000  Code  00FC2FF0
  20. Stack:   Reg   0027368E  Lower 00272BFC  Upper 002736EC
  21. CPURegs: PC    00FC08F4  SR    0010
  22. D: 0023D158 00000000 002721CC 00272778 00000009 00000052 00000057 00272B9C
  23. A: 00FF4134 00272B40 00C04EC8 00FF9FF2 00FF4648 00C00240 00C00276
  24. Process Dependent ---------------------------------------------
  25. SegList     $00200C6C  StackSize   $00000AF0  GlobVec $00C04EC8
  26. TaskNum             0  StackBase   $00272BFC  Result2         0
  27. CurrentDir  $00000000  CIS         $00000000  COS     $00000000
  28. ConsoleTask $0022F264  FileSysTask $00C00ADC  CLI     $00000000
  29. ReturnAddr  $002736E8  PktWait     $00000000
  30. */
  31.  
  32. parse arg name '0x' tsk .
  33. NULL = "00000000"x
  34.  
  35. if (name = '?') then
  36.    do
  37.    do i = 2 to 11
  38.       'd "'||strip(sourceline(i),'T',"0a"x) '"'
  39.    end
  40.    exit(0)
  41.    end
  42. else if (name ~= '') then
  43.    do
  44.    taskbase = findtask(name)
  45.    name = "'"||name||"'"
  46.    end
  47. else if (tsk ~= '') then
  48.    do
  49.    name = right(tsk,8,'0')
  50.    taskbase = x2c(name)
  51.    name = '0x'||name
  52.    end
  53. else
  54.    do
  55.    options results
  56.    'd a7 %08x'
  57.    sp = left(result,8)
  58.    'tasks'
  59.    tasklist = result
  60.    options
  61.  
  62.    /* Now figure out where the stack pointer should be */
  63.    sp = c2x(offset(x2c(sp),-118))
  64.  
  65.    place = index(tasklist,sp)
  66.    if (place = 0) then place = 87
  67.    name = substr(tasklist, place-33, 8)
  68.    taskbase = x2c(name)
  69.    name = '0x'||name
  70.    end
  71.  
  72. statenm.0 = 'invalid'
  73. statenm.1 = 'added'
  74. statenm.2 = 'run'
  75. statenm.3 = 'ready'
  76. statenm.4 = 'wait'
  77. statenm.5 = 'except'
  78. statenm.6 = 'removed'
  79.  
  80. type      = c2d(import(offset(taskbase,8),1))
  81. if (type ~= 13 & type ~= 1) then do
  82.    'd' '"'||name 'is not a valid process"'
  83.    exit(0)
  84. end
  85.  
  86. name      = "'"||import(import(offset(taskbase,10),4))||"'"
  87. state     = c2d(import(offset(taskbase,15),1))
  88. statename = statenm.state
  89. pri       = c2d(import(offset(taskbase,9),1))
  90. 'd' '"'||name 'in' statename 'state at priority' pri '"'
  91.  
  92. flags     = c2x(import(offset(taskbase,14),1))
  93. idnest    = c2d(import(offset(taskbase,16),1),1)
  94. tdnest    = c2d(import(offset(taskbase,17),1),1)
  95. 'd' '"Type' type ' Flags' flags ' IDNestCnt' idnest ' TDNestCnt' tdnest '"'
  96.  
  97. sigalloc  = c2x(import(offset(taskbase,18),4))
  98. sigwait   = c2x(import(offset(taskbase,22),4))
  99. sigrec    = c2x(import(offset(taskbase,26),4))
  100. sigexcept = c2x(import(offset(taskbase,30),4))
  101. 'd' '"Signal:  Alloc' sigalloc ' Wait ' sigwait ' Recvd' sigrec ' Except' sigexcept '"'
  102.  
  103. trapdata  = c2x(import(offset(taskbase,46),4))
  104. trapcode  = c2x(import(offset(taskbase,50),4))
  105. trapalloc = c2x(import(offset(taskbase,34),2))
  106. trapable  = c2x(import(offset(taskbase,36),2))
  107. 'd' '"Trap:    Data ' trapdata ' Code ' trapcode ' Alloc' trapalloc ' Able' trapable '"'
  108.  
  109. excptdata = c2x(import(offset(taskbase,38),4))
  110. excptcode = c2x(import(offset(taskbase,42),4))
  111. 'd' '"Except:  Data ' excptdata ' Code ' excptcode '"'
  112.  
  113. sp        = import(offset(taskbase,54),4)
  114. spreg     = c2x(sp)
  115. splower   = c2x(import(offset(taskbase,58),4))
  116. spupper   = c2x(import(offset(taskbase,62),4))
  117. 'd' '"Stack:   Reg  ' spreg ' Lower' splower ' Upper' spupper '"'
  118.  
  119. if (state >= 3 & state <= 6) then do
  120. pc = c2x(import(sp, 4))
  121. sr = c2x(import(offset(sp,4),2))
  122. 'd' '"CPURegs: PC   ' pc ' SR   ' sr '"'
  123.  
  124. dregs = c2x(import(offset(sp,6), 32))
  125. dregs = insert(' ', dregs, 56);
  126. dregs = insert(' ', dregs, 48);
  127. dregs = insert(' ', dregs, 40);
  128. dregs = insert(' ', dregs, 32);
  129. dregs = insert(' ', dregs, 24);
  130. dregs = insert(' ', dregs, 16);
  131. dregs = insert(' ', dregs, 8);
  132. 'd' '"D:' dregs '"'
  133.  
  134. aregs = c2x(import(offset(sp,38), 28))
  135. aregs = insert(' ', aregs, 48);
  136. aregs = insert(' ', aregs, 40);
  137. aregs = insert(' ', aregs, 32);
  138. aregs = insert(' ', aregs, 24);
  139. aregs = insert(' ', aregs, 16);
  140. aregs = insert(' ', aregs, 8);
  141. 'd' '"A:' aregs '"'
  142. end
  143.  
  144. if type = 13 then do
  145. 'd' '"Process Dependent ----------------------------------------------"'
  146.  
  147. seglist   = "$"||c2x(d2c(c2d(import(offset(taskbase,128),4))*4,4))
  148. stacksize = right(c2d(import(offset(taskbase,132),4)), 9)
  149. globvec   = "$"||c2x(import(offset(taskbase,136),4))
  150. 'd' '"SegList    ' seglist ' StackSize  ' stacksize ' GlobVec ' globvec '"'
  151.  
  152. tasknum   = right(c2d(import(offset(taskbase,140),4)), 9)
  153. stackbase = "$"||c2x(d2c(c2d(import(offset(taskbase,144),4))*4,4))
  154. result2   = right(c2d(import(offset(taskbase,148),4)), 9)
  155. 'd' '"TaskNum    ' tasknum ' StackBase  ' stackbase ' Result2 ' result2 '"'
  156.  
  157. curdir    = "$"||c2x(d2c(c2d(import(offset(taskbase,152),4))*4,4))
  158. cis       = "$"||c2x(d2c(c2d(import(offset(taskbase,156),4))*4,4))
  159. cos       = "$"||c2x(d2c(c2d(import(offset(taskbase,160),4))*4,4))
  160. 'd' '"CurrentDir ' curdir ' CIS        ' cis ' COS     ' cos '"'
  161.  
  162. contask   = "$"||c2x(import(offset(taskbase,164),4))
  163. filesys   = "$"||c2x(import(offset(taskbase,168),4))
  164. cli       = "$"||c2x(d2c(c2d(import(offset(taskbase,172),4))*4,4))
  165. 'd' '"ConsoleTask' contask ' FileSysTask' filesys ' CLI     ' cli '"'
  166.  
  167. retaddr   = "$"||c2x(import(offset(taskbase,180),4))
  168. pktwait   = "$"||c2x(import(offset(taskbase,184),4))
  169. 'd' '"ReturnAddr ' retaddr ' PktWait    ' pktwait '"'
  170. end
  171.  
  172. exit 0
  173.  
  174. /* Locate a task in the system based upon the name */
  175. findtask:
  176.   parse arg name
  177.   execbase = import("00000004"x,4)
  178.   liboff = 420
  179.   nodebase = import(offset(execbase, liboff), 4)
  180.  
  181. do while(import(nodebase,4) ~= NULL)
  182.    if import(import(offset(nodebase,10),4)) = name then return nodebase
  183.    nodebase = import(nodebase,4)
  184. end
  185.  
  186.   liboff = 406
  187.   nodebase = import(offset(execbase, liboff), 4)
  188.  
  189. do while(import(nodebase,4) ~= NULL)
  190.    if import(import(offset(nodebase,10),4)) = name then return nodebase
  191.    nodebase = import(nodebase,4)
  192. end
  193.  
  194. 'd' '"Could not find process' name||'"'
  195. exit(0)
  196.